package com.esp.soccertutor.util;


import com.esp.soccertutor.fbreader.fbreader.ChangeFontAlignment;
import com.esp.soccertutor.fbreader.fbreader.FBReaderApp;
import com.esp.soccertutor.zlibrary.core.application.ZLApplication;
import com.esp.soccertutor.zlibrary.core.options.ZLIntegerRangeOption;
import com.esp.soccertutor.zlibrary.core.options.ZLStringOption;
import com.esp.soccertutor.zlibrary.text.model.ZLTextAlignmentType;

public class Bean {
	
	
	private static String setFontName=Const.strFontName[0];
	private static String setAlignment=Const.strAlignment[4];
	
	public static void setFontName(int index){
		if(index!=-1){
			setFontName=Const.strFontName[index];
			new ZLStringOption("Style","Base:fontFamily","Droid Sans").setValue(Const.strFontName[index]);
			Log.print("Bean : : setFontName",Const.strFontName[index]);
			
		}else{
			setFontName=Const.strFontName[0];
			new ZLStringOption("Style","Base:fontFamily","Droid Sans").setValue(Const.strFontName[index]);
			Log.print("Bean : : setFontNameDefault",Const.strFontName[index]);

		}
		
	}
	public static String getFontName(){
		Log.print("Bean ::getFontName",""+setFontName);
		return setFontName;
	}
	public static int getFontIndex(String fontname){
		int index;
		for(index=0;index<Const.strFontName.length;index++){
			if(Const.strFontName[index].equals(fontname))
				break;
		}
		return index;
	}
	
	public static void setAlignment(int index){
		
		if(index!=-1){
			
			setAlignment=Const.strAlignment[index];
			new ZLIntegerRangeOption("Style","Base:alignment",1,4,ZLTextAlignmentType.ALIGN_JUSTIFY).setValue(index);
			Log.print("Bean : : setAlignment",Const.strAlignment[index]);
			FBReaderApp fbReader = (FBReaderApp)ZLApplication.Instance();
			new ChangeFontAlignment(fbReader,index).run();
			
		}else{
			setAlignment=Const.strAlignment[4];
			new ZLIntegerRangeOption("Style","Base:alignment",1,4,ZLTextAlignmentType.ALIGN_JUSTIFY).setValue(4);
			Log.print("Bean : : setAlignmentDefault","Justify");
			FBReaderApp fbReader = (FBReaderApp)ZLApplication.Instance();
			new ChangeFontAlignment(fbReader,4).run();
		}
	}
	public static int getAlignmentIndex(String alignment){
		int index;
		for(index=0;index<Const.strAlignment.length;index++){
			if(Const.strAlignment[index].equals(alignment))
				break;
		}
		return index;
		
	}
	public static String getAlignment(){
		
		Log.print("Bean ::getAlignment",""+ Const.strAlignment[new ZLIntegerRangeOption("Style","Base:alignment",1,4,ZLTextAlignmentType.ALIGN_JUSTIFY).getValue()]);
		
		return Const.strAlignment[new ZLIntegerRangeOption("Style","Base:alignment",1,4,ZLTextAlignmentType.ALIGN_JUSTIFY).getValue()];
		
	}
	
	public static void setThemeBg(String theme,int index){
		
		if(theme.equals("DAY")){
			
			new ZLStringOption("Colors","defaultLight:Wallpaper","wallpapers/sepia.jpg").setValue("wallpapers/"+Const.WALLPAPER_DAY_NAME[index]);
		}else{
			new ZLStringOption("Colors","defaultDark:Wallpaper","wallpapers/bg_black.png").setValue("wallpapers/"+Const.WALLPAPER_NIGHT_NAME[index]);
		}
	}
	public static int getWallIndex(String name,String theme){
		
		if(theme.equals("DAY")){
			int index;
			for(index=0;index<Const.WALLPAPER_DAY_NAME.length;index++)
			{
				if(Const.WALLPAPER_DAY_NAME[index].equals(name))
					break;
			}
			return index;
		}else{
				
			int index;
			for(index=0;index<Const.WALLPAPER_NIGHT_NAME.length;index++)
			{
				if(Const.WALLPAPER_NIGHT_NAME[index].equals(name))
					break;
			}
			return index;
			
		}
		
	}
	public static String getThemeBg(String theme){
		
		if(theme.equals("DAY")){
			String temp=new ZLStringOption("Colors","defaultLight:Wallpaper","wallpapers/sepia.jpg").getValue();
			
			return temp.substring(temp.indexOf("/")+1);
			
		}else{
			String temp=new ZLStringOption("Colors","defaultDark:Wallpaper","wallpapers/bg_black.png").getValue();
			return temp.substring(temp.indexOf("/")+1);
		}
	}
	
	public static int getIndex(String[]name,String strname){
		int index;
		for(index=0;index<name.length;index++){
			if(name[index].equals(strname))
				break;
		}
		return index;
	}
	
	
}
